// $Id: transport.h 88 2011-10-17 18:00:11Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef NIORTSP_TRANSPORT_H_
#define NIORTSP_TRANSPORT_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <netinet/in.h>

struct event_base;

struct timeval;

struct zcbuffer;

enum niortp_transport_type {
	NIORTP_TRANSPORT_UNKNOWN,
	NIORTP_TRANSPORT_UDP_UNICAST,
	NIORTP_TRANSPORT_INTERLEAVED,
};

const char *niortp_transport_type_to_str(enum niortp_transport_type type);

struct niortp_transport_address {
	struct sockaddr_in rtp, rtcp;
};

struct niortp_transport_param {
	struct sockaddr_in remote;
	enum niortp_transport_type type;
	unsigned char payload_type;
	struct niortp_transport_address address;
	unsigned int mtu;
};

struct niortp_transport_stat {
	unsigned int instances; // number of units grouped by timestamp; e.g. a video frame
	struct {
		unsigned int min, max;
	} duration; // time of arrival between instances; e.g. duration of video frame
	struct {
		unsigned int units;
		unsigned int bytes;
	} incoming, dropped, outgoing, rtp, rtcp;
};

typedef void *(*niortp_transport_create)(struct event_base *evbase);

typedef void (*niortp_transport_destroy)(void *obj);

typedef int (*niortp_transport_setup)(void *obj, int fd,
		struct niortp_transport_param *param);

typedef int (*niortp_transport_teardown)(void *obj);

typedef int (*niortp_transport_send)(void *obj,
		const struct timeval *timestamp, struct zcbuffer *frame);

typedef int (*niortp_transport_pending)(void *obj);

typedef int (*niortp_transport_next)(void *obj);

typedef int (*niortp_transport_stat)(void *obj,
		struct niortp_transport_stat *stat);

struct niortp_transport {
	niortp_transport_create create;
	niortp_transport_destroy destroy;
	niortp_transport_setup setup;
	niortp_transport_teardown teardown;
	niortp_transport_send send;
	niortp_transport_pending pending;
	niortp_transport_next next;
	niortp_transport_stat stat;
};

#ifdef __cplusplus
}
#endif

#endif /* NIORTSP_TRANSPORT_H_ */
